home *** CD-ROM | disk | FTP | other *** search
- Path: xanth!nic.MR.NET!hal!ncoast!allbery
- From: tr@wind.bellcore.com (tom reingold)
- Newsgroups: comp.sources.misc
- Subject: v05i013: Statistical awk scripts
- Message-ID: <8810221430.AA18345@wind.bellcore.com>
- Date: 28 Oct 88 02:44:26 GMT
- Sender: allbery@ncoast.UUCP
- Reply-To: tr@wind.bellcore.com (tom reingold)
- Lines: 105
- Approved: allbery@ncoast.UUCP
-
- Posting-number: Volume 5, Issue 13
- Submitted-by: "tom reingold" <tr@wind.bellcore.com>
- Archive-name: awkstats
-
- [This was deferred for a bit in memory of the Xenix smail mods posting that
- had to be superseded time after time after... you get the idea. I prefer
- making sure the posting is stable first.... ++bsa]
-
- You know how it goes. You clean your code up just to make it look
- pretty and you break it. Ok, so this version works. I hope you
- haven't posted yesterday's version.
-
- Thanks!
-
- #! /bin/sh
- # This is a shell archive, meaning:
- # 1. Remove everything above the #! /bin/sh line.
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh (not csh) to create the files:
- # README
- # stats1.awk
- # stats2.awk
- # This archive created: Sat Oct 22 10:27:35 1988
- # By: tom reingold (Bellcore, Morristown, Noo Joizy)
- export PATH; PATH=/bin:$PATH
- if test -f 'README'
- then
- echo shar: will not over-write existing file "'README'"
- else
- cat << \SHAR_EOF > 'README'
-
- Here is an awk script I wrote for the hell of it because I am home
- sick today. It computes the standard boring univariate statistics.
- I have enclosed two versions. "stats1.awk" requires the new new
- version of awk, which has user-definable functions. (MKS awk allows
- this too!) In stats1.awk, I define a function called pow, which
- in and of itself, is useful. "stats2.awk" doesn't require the new
- awk. It may actually be faster too since it doesn't do an interpreted
- function call. But it's not as cool.
-
- Tom Reingold
- PAPERNET: |INTERNET: tr@bellcore.bellcore.com
- Bell Communications Research |UUCP-NET: bellcore!tr
- 445 South St room 2L350 |SOUNDNET: (201) 829-4622 [work],
- Morristown, NJ 07960-1910 | (201) 287-2345 [home]
- SHAR_EOF
- if test 799 -ne "`wc -c < 'README'`"
- then
- echo shar: error transmitting "'README'" '(should have been 799 characters)'
- fi
- fi # end of overwriting check
- if test -f 'stats1.awk'
- then
- echo shar: will not over-write existing file "'stats1.awk'"
- else
- cat << \SHAR_EOF > 'stats1.awk'
- {
- a[NR] = $1
- sum += a[NR]
- sumsq += pow(a[NR], 2.0)
- }
- END {
- mean = (sum / NR)
- stddev = sqrt((sumsq / NR) - pow(mean, 2.0))
- printf "sum is %1.2f, mean is %1.2f, n is %d, stddev is %1.3f\n", \
- sum, mean, NR, stddev
- }
- func pow(mantissa, exponent)
- {
- if (exponent == 0)
- return(1)
- if (mantissa == 0)
- return(0)
- return(exp(exponent * log(mantissa)))
- }
- SHAR_EOF
- if test 358 -ne "`wc -c < 'stats1.awk'`"
- then
- echo shar: error transmitting "'stats1.awk'" '(should have been 358 characters)'
- fi
- fi # end of overwriting check
- if test -f 'stats2.awk'
- then
- echo shar: will not over-write existing file "'stats2.awk'"
- else
- cat << \SHAR_EOF > 'stats2.awk'
- {
- a[NR] = $1
- sum += a[NR]
- sumsq += (a[NR] * a[NR])
- }
- END {
- mean = (sum / NR)
- stddev = sqrt((sumsq / NR) - (mean * mean))
- printf "sum is %1.2f, mean is %1.2f, n is %d, stddev is %1.3f\n", \
- sum, mean, NR, stddev
- }
- SHAR_EOF
- if test 221 -ne "`wc -c < 'stats2.awk'`"
- then
- echo shar: error transmitting "'stats2.awk'" '(should have been 221 characters)'
- fi
- fi # end of overwriting check
- # End of shell archive
- exit 0
-